﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 牌库 一副牌
/// </summary>
public class CardModel
{
    /// <summary>
    /// 一副牌
    /// </summary>
    private  Queue<Card> CardLibrary = new Queue<Card>();
    private CharacterType CTpye;

    /// <summary>
    /// 牌库剩余的数量
    /// </summary>
    public int CardCount
    {
        get { return CardLibrary.Count; }
    }

    /// <summary>
    /// 初始化牌库 54张
    /// </summary>
    public void InitCardLibrary()
    {
        for (int color = 1; color < 5; color++)
        {
            for (int weight = 0; weight < 13; weight++)
            {
                Colors c = (Colors)color;
                Weight w = (Weight)weight;
                string name = c.ToString() + w.ToString();
                Card card = new Card(name, c, w, CTpye);
                CardLibrary.Enqueue(card);//把每一张牌入队
            }
        }
        Card Ljoker = new Card("LJoker", Colors.None, Weight.LJoker, CTpye);
        Card Sjoker = new Card("SJoker", Colors.None, Weight.SJoker, CTpye);
        CardLibrary.Enqueue(Ljoker);
        CardLibrary.Enqueue(Sjoker);
    }
    /// <summary>
    /// 发牌
    /// </summary>
    public Card DealCard(CharacterType Sendto)
    {
        Card card;
        card = CardLibrary.Dequeue();
        card.BelongTo = Sendto;      
        return card;
    }
    /// <summary>
    /// 回收牌
    /// </summary>
    /// <param name="card"></param>
    public void RecycleCard(Card card)
    {
        CardLibrary.Enqueue(card);
        card.BelongTo = CTpye;
    }
    /// <summary>
    /// 洗牌
    /// </summary>
    public void Shuffle()
    {
        List<Card> newList = new List<Card>();
        foreach (Card card in CardLibrary)
        {            
           int index = Random.Range(0, newList.Count + 1);
           newList.Insert(index, card);
        }
        CardLibrary.Clear();
        foreach (Card card in newList)
        {
            CardLibrary.Enqueue(card);
        }
        newList.Clear();
    }
}
